from git import Repo
from git.objects import Commit
import logging

logger = logging.getLogger(__name__)


class GitRepoHandler:
    def __init__(self, path):
        try:
            self.repo = Repo(path)
        except Exception as e:
            logger.exception("初始化 Git 仓库失败")
            raise RuntimeError("无法打开 Git 仓库")

    def get_commits(self, max_count=100) -> list[Commit]:
        return list(self.repo.iter_commits('HEAD', max_count=max_count))
